package cn.edu.szpt.qqdemov3.adapters;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.List;

import cn.edu.szpt.qqdemov3.R;
import cn.edu.szpt.qqdemov3.beans.QQMessageBean;

public class QQMessageAdapter extends BaseAdapter {
    private Context context;
    private List<QQMessageBean> data;

    public QQMessageAdapter(Context context, List<QQMessageBean> data) {
        this.context = context;
        this.data = data;
    }



    @Override
    public int getCount() {
        return data.size();
    }

    @Override
    public Object getItem(int position) {
        return data.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if(convertView==null){
            convertView = LayoutInflater.from(context).inflate(R.layout.item_qqmessage,parent,false);
            holder = new ViewHolder();
            holder.img_qqicon = convertView.findViewById(R.id.img_qqicon);
            holder.tv_qqname = convertView.findViewById(R.id.tv_qqname);
            holder.tv_lasttitle = convertView.findViewById(R.id.tv_lasttitle);
            holder.tv_lastmsgtime= convertView.findViewById(R.id.tv_lastmsgtime);
            holder.tv_notreadmsgcount = convertView.findViewById(R.id.tv_notreadmsgcount);
            convertView.setTag(holder);
        }else{
            holder = (ViewHolder) convertView.getTag();
        }
        QQMessageBean bean = data.get(position);

        holder.img_qqicon.setImageResource(bean.getQq_icon());
        holder.tv_qqname.setText(bean.getQq_name());
        holder.tv_lasttitle.setText(bean.getLasttitle());
        holder.tv_lastmsgtime.setText(bean.getLastmsg_time());
        holder.tv_notreadmsgcount.setText(bean.getNotreadmsg_count() +"");

        return convertView;
    }

    static  class ViewHolder{
        ImageView img_qqicon;
        TextView tv_qqname;
        TextView tv_lasttitle;
        TextView tv_lastmsgtime;
        TextView tv_notreadmsgcount;
    }
}
